<template>
  <header id="header" :style="{ margin: margins + 'px' }">
    <div class="conWidth head-box">
      <div class="hander-left">
        <span>主页</span>
        <span>博客</span>
      </div>
      <div class="hander-right">
        <span>注册</span>
        <span>登录</span>
      </div>
    </div>
    <div class="nav centerBox" v-if="isNav">
      <div class="conWidth nav-box">
        <div class="nav-left">
          <div class="logo">logo</div>
          <!-- 导航列表 -->
          <div class="nav_list">
            <span v-for="(item, index) in webPage" :key="index">{{
              item.webPageName
            }}</span>
          </div>
        </div>
        <!-- 搜索 -->
        <div class="nav-right centerBox">
          <div class="Search">
            <el-input placeholder="Search" v-model="keyword" />
            <i class="el-icon-search" @click="search" />
          </div>
        </div>
      </div>
    </div>
  </header>
</template>
<script>
export default {
  props: {
    isNav: {
      type: Boolean,
      default: true,
    },
    margins: {
      type: String,
      default: "0 0 80px 0",
    },
  },
  data() {
    return {
      webPage: [], // 导航
      keyword: "",
    };
  },
  created() {
    this.getWebPage();
  },
  methods: {
    getWebPage() {
      this.$http.get("api/webPage/getWebPageList").then((res) => {
        this.webPage = res.data;
      });
    },
    search() {
      this.$http
        .get("api/search", { params: { keyword: this.keyword, size: 10, current: 1} })
        .then((res) => {
          this.$emit("search", res.data);
        });
    },
  },
};
</script>
<style scoped lang="less">
#header {
  height: 30px;
  background: #000;
  margin-bottom: 80px;
  .head-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    div {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 30px;
      span {
        cursor: pointer;
      }
    }
    .hander-left {
      span {
        margin-right: 20px;
      }
    }
    .hander-right {
      span {
        margin-left: 20px;
      }
    }
  }
  .nav {
    position: relative;
    width: 100%;
    background: rgba(0, 0, 0, 0.85);
    height: 50px;
    z-index: 9998;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
    background: #fff;
    .nav-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .nav-left {
      display: flex;
      align-items: center;
      font-size: 16px;
      .logo {
        width: 150px;
      }
      span {
        margin: 0 25px;
        cursor: pointer;
      }
    }
    .nav-right {
      .Search {
        display: flex;
        width: 100px;
        border: 1px solid #ccc;
        padding: 5px 10px;
        border-radius: 50px;
      }
    }
  }
}
</style>